home *** CD-ROM | disk | FTP | other *** search
- program TstBits;
-
- {$IFDEF Win32}
- {$APPTYPE CONSOLE}
- {$ENDIF}
-
- uses
- {$IFDEF Windows}
- WinCrt,
- {$ENDIF}
- SysUtils,
- AABitSet in 'AABitSet.pas';
-
- var
- MyBitSet : TaaBitSet;
- OtherBitSet : TaaBitSet;
- i : integer;
- begin
- writeln('Testing bitset methods');
- MyBitSet := nil;
- OtherBitSet := nil;
- try
- MyBitSet := TaaBitSet.Create(21);
-
- {set every other bit}
- writeln('..setting bits');
- for i := 0 to 20 do
- if Odd(i) then
- MyBitSet[i] := true;
- for i := 0 to 20 do
- if Odd(i) then begin
- if not MyBitSet[i] then
- writeln('Error at ', i);
- end
- else begin
- if MyBitSet[i] then
- writeln('Error at ', i);
- end;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- {not the bitset}
- writeln('..not bitset');
- MyBitSet.NotBitSet;
- for i := 0 to 20 do
- if not Odd(i) then begin
- if not MyBitSet[i] then
- writeln('Error at ', i);
- end
- else begin
- if MyBitSet[i] then
- writeln('Error at ', i);
- end;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- {clear every other bit}
- writeln('..clearing bits');
- for i := 0 to 20 do
- if not Odd(i)then
- MyBitSet[i] := false;
- for i := 0 to 20 do
- if MyBitSet[i] then
- writeln('Error at ', i);
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- {set and clear all bits}
- writeln('..set and then clear all bits');
- MyBitSet.SetAllBits;
- for i := 0 to 20 do
- if not MyBitSet[i] then
- writeln('Error at ', i);
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
- MyBitSet.ClearAllBits;
- for i := 0 to 20 do
- if MyBitSet[i] then
- writeln('Error at ', i);
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- {and, or, xor with another bitset}
- writeln('..and with other bitset');
- OtherBitSet := TaaBitSet.Create(21);
- for i := 0 to 20 do
- if Odd(i) then
- OtherBitSet[i] := true;
- for i := 0 to 20 do
- if (i mod 5) = 0 then
- MyBitSet[i] := true;
- MyBitSet.AndBitSet(OtherBitSet);
- writeln('set bits should be 5 and 15');
- for i := 0 to 20 do
- if MyBitSet[i] then
- write(i:3);
- writeln;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- writeln('..or with other bitset');
- MyBitSet.ClearAllBits;
- for i := 0 to 20 do
- if (i mod 5) = 0 then
- MyBitSet[i] := true;
- MyBitSet.OrBitSet(OtherBitSet);
- writeln('set bits should be 0, 1, 3, 5, 7, 9, 10, 11, 13, 15, 17, 19, 20');
- for i := 0 to 20 do
- if MyBitSet[i] then
- write(i:3);
- writeln;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- writeln('..xor with other bitset');
- MyBitSet.ClearAllBits;
- for i := 0 to 20 do
- if (i mod 5) = 0 then
- MyBitSet[i] := true;
- MyBitSet.XorBitSet(OtherBitSet);
- writeln('set bits should be 0, 1, 3, 7, 9, 10, 11, 13, 17, 19, 20');
- for i := 0 to 20 do
- if MyBitSet[i] then
- write(i:3);
- writeln;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- {get the next eleven 'free' bits}
- writeln('..get the next eleven bits');
- writeln(' should be 2, 4, 5, 6, 8, 12, 14, 15, 16, 18, -1');
- for i := 1 to 11 do
- write(MyBitSet.GetNextBit:3);
- writeln;
- writeln('SetBitCount: ', MyBitSet.SetBitCount);
-
- finally
- MyBitSet.Free;
- OtherBitSet.Free;
- end;
- writeln('Done: press Enter');
- readln;
- end.
-